home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_200 / 259_01 / aprofile.asm < prev    next >
Encoding:
Assembly Source File  |  1988-02-23  |  8.1 KB  |  357 lines

  1.          page     ,132
  2.          name     APROFILE
  3.  
  4. ;   APROFILE.ASM - Low level application profile generator.
  5. ;
  6. ;      V01.00  010788  Bob Withers   Program originally complete
  7. ;
  8.  
  9. MSDOS         equ     21h
  10. TIMER_SET_CNT     equ     36h
  11.  
  12. TIMER_INT_CNT     equ     32
  13. TIMER_CNT_WORD     equ     0800h
  14. ;             TIMER_INT_CNT     TIMER_CNT_WORD   Int per Sec
  15. ;                   1         0000h          18.2
  16. ;                   2         8000h          36.4
  17. ;                   4         4000h          72.8
  18. ;                   8         2000h         145.6
  19. ;                  16         1000h         291.2
  20. ;                  32         0800h         582.4
  21. ;                  64         0400h        1164.8
  22.  
  23. TIMER_CTL_PORT     equ     43h
  24. TIMER_DATA_PORT  equ     40h
  25. I8259_EOI_PORT     equ     20h
  26. EOI_CODE     equ     20h
  27.  
  28.          if1
  29.          ifdef     LMODEL
  30.          %out     Assembling for LARGE model
  31.          else
  32.          ifdef     MMODEL
  33.          %out     Assembling for MEDIUM model
  34.          else
  35.          ifdef     CMODEL
  36.          %out     Assembling for COMPACT model
  37.          else
  38.          %out     Assembling for SMALL model
  39.          endif
  40.          endif
  41.          endif
  42.          endif
  43.  
  44. BegCodeSeg     macro     name
  45.          ifdef     LMODEL
  46. name&_TEXT     segment byte public 'CODE'
  47.          assume  cs:&name&_TEXT
  48.          else
  49.          ifdef     MMODEL
  50. name&_TEXT      segment byte public 'CODE'
  51.          assume  cs:&name&_TEXT
  52.          else
  53.          ifdef     CMODEL
  54. _TEXT         segment byte public 'CODE'
  55.          assume  cs:_TEXT
  56.          else
  57. _TEXT         segment byte public 'CODE'
  58.          assume  cs:_TEXT
  59.          endif
  60.          endif
  61.          endif
  62.          endm
  63.  
  64. EndCodeSeg     macro     name
  65.          ifdef     LMODEL
  66. name&_TEXT     ends
  67.          else
  68.          ifdef     MMODEL
  69. name&_TEXT     ends
  70.          else
  71.          ifdef     CMODEL
  72. _TEXT         ends
  73.          else
  74. _TEXT         ends
  75.          endif
  76.          endif
  77.          endif
  78.          endm
  79.  
  80. Entry         macro     name
  81.          public  _&name
  82.          ifdef     LMODEL
  83. _&name         proc     far
  84.          else
  85.          ifdef     MMODEL
  86. _&name         proc     far
  87.          else
  88.          ifdef     CMODEL
  89. _&name         proc     near
  90.          else
  91. _&name         proc     near
  92.          endif
  93.          endif
  94.          endif
  95.          push     bp
  96.          mov     bp,sp
  97.          push     si
  98.          push     di
  99.          push     es
  100.          endm
  101.  
  102. Exit         macro     name
  103.          pop     es
  104.          pop     di
  105.          pop     si
  106.          pop     bp
  107.          ret
  108. _&name         endp
  109.          endm
  110.  
  111.          ifdef     LMODEL
  112. Parm1         struc
  113. Save_BP1     dw     ?
  114. Ret_Addr1     dd     ?
  115. P_TotSegs     dw     ?
  116. P_SegTab     dd     ?
  117. Parm1         ends
  118.          else
  119.          ifdef     MMODEL
  120. Parm1         struc
  121. Save_BP1     dw     ?
  122. Ret_Addr1     dd     ?
  123. P_TotSegs     dw     ?
  124. P_SegTab     dd     ?
  125. Parm1         ends
  126.          else
  127.          ifdef     CMODEL
  128. Parm1         struc
  129. Save_BP1     dw     ?
  130. Ret_Addr1     dw     ?
  131. P_TotSegs     dw     ?
  132. P_SegTab     dd     ?
  133. Parm1         ends
  134.          else
  135. Parm1         struc
  136. Save_BP1     dw     ?
  137. Ret_Addr1     dw     ?
  138. P_TotSegs     dw     ?
  139. P_SegTab     dd     ?
  140. Parm1         ends
  141.          endif
  142.          endif
  143.          endif
  144.  
  145. Parm2         struc
  146. Save_BP2     dw     ?
  147. Int_Addr     dd     ?
  148. Flags         dw     ?
  149. Parm2         ends
  150.  
  151. Seg1         struc
  152. SegAddr      dw     ?
  153. LinCnt         dw     ?
  154. PubCnt         dw     ?
  155. LinPtr         dd     ?
  156. PubPtr         dd     ?
  157. Seg1         ends
  158.  
  159. Ofs1         struc
  160. OfsAddr      dw     ?
  161. OfsLoCnt     dw     ?
  162. OfsHiCnt     dw     ?
  163. Ofs1         ends
  164.  
  165.  
  166.          BegCodeSeg PRFA
  167.  
  168. IntCnt         dw     TIMER_INT_CNT
  169. TotSegs      dw     0
  170. SegTab         dd     0
  171. OldInt08     dd     0
  172. OtherCntLo     dw     0
  173. OtherCntHi     dw     0
  174. BiosCntLo     dw     0
  175. BiosCntHi     dw     0
  176. DosCntLo     dw     0
  177. DosCntHi     dw     0
  178. HitCntLo     dw     0
  179. HitCntHi     dw     0
  180.  
  181. ;
  182. ;     void cdecl PrfInit(TotSegs, SegTab)
  183. ;     unsigned      TotSegs;
  184. ;     char     *SegTab;
  185. ;
  186.          Entry     PrfInit
  187.          mov     ax,[bp].P_TotSegs     ;Get my parameters
  188.          mov     TotSegs,ax         ;        .
  189.          les     ax,[bp].P_SegTab     ;        .
  190.          mov     word ptr SegTab,ax     ;        .
  191.          mov     word ptr SegTab+2,es     ;        .
  192.          mov     ax,3508h         ;Get current timer vector
  193.          int     MSDOS             ;        .
  194.          mov     word ptr OldInt08,bx     ;        .
  195.          mov     word ptr OldInt08+2,es  ;        .
  196.          mov     ax,2508h         ;Setup my timer vector addr
  197.          push     ds             ;        .
  198.          push     cs             ;        .
  199.          pop     ds             ;        .
  200.          mov     dx,offset Int08     ;        .
  201.          int     MSDOS             ;        .
  202.          pop     ds             ;        .
  203.          mov     al,TIMER_SET_CNT     ;Set timer 0 interrupt rate
  204.          out     TIMER_CTL_PORT,al     ;    to higher speed
  205.          mov     ax,TIMER_CNT_WORD     ;        .
  206.          out     TIMER_DATA_PORT,al     ;        .
  207.          mov     al,ah             ;        .
  208.          out     TIMER_DATA_PORT,al     ;        .
  209.          Exit     PrfInit
  210.  
  211.  
  212. ;
  213. ;     unsigned long cdecl PrfTerm()
  214. ;
  215.          Entry     PrfTerm
  216.          mov     al,36h          ;Reset timer 0 interrupt
  217.          out     TIMER_CTL_PORT,al     ;    rate to normal
  218.          xor     al,al             ;        .
  219.          out     TIMER_DATA_PORT,al     ;        .
  220.          nop                 ;        .
  221.          out     TIMER_DATA_PORT,al     ;        .
  222.          mov     ax,2508h         ;Restore old timer vector
  223.          push     ds             ;        .
  224.          lds     dx,OldInt08         ;        .
  225.          int     MSDOS             ;        .
  226.          pop     ds             ;        .
  227.          mov     ax,OtherCntLo         ;Return 'other' hit count
  228.          mov     dx,OtherCntHi         ;        .
  229.          Exit     PrfTerm
  230.  
  231.  
  232. ;
  233. ;     unsigned long cdecl PrfDosCnt()
  234. ;
  235.          Entry     PrfDosCnt
  236.          mov     ax,DosCntLo         ;Return 'DOS' hit count
  237.          mov     dx,DosCntHi         ;        .
  238.          Exit     PrfDosCnt
  239.  
  240.  
  241. ;
  242. ;     unsigned long cdecl PrfBiosCnt()
  243. ;
  244.          Entry     PrfBiosCnt
  245.          mov     ax,BiosCntLo         ;Return 'BIOS' hit count
  246.          mov     dx,BiosCntHi         ;        .
  247.          Exit     PrfBiosCnt
  248.  
  249.  
  250. ;
  251. ;     unsigned long cdecl PrfHitCnt()
  252. ;
  253.          Entry     PrfHitCnt
  254.          mov     ax,HitCntLo         ;Return 'appl' hit count
  255.          mov     dx,HitCntHi         ;        .
  256.          Exit     PrfHitCnt
  257.  
  258.  
  259. Int08         proc     far
  260.          push     bp             ;Set up stack frame
  261.          mov     bp,sp             ;        .
  262.          push     ax             ;Save all registers
  263.          push     bx             ;        .
  264.          push     cx             ;        .
  265.          push     dx             ;        .
  266.          push     si             ;        .
  267.          push     di             ;        .
  268.          push     es             ;        .
  269.          push     ds             ;        .
  270.          lds     si,[bp].Int_Addr     ;Addr of interrupt
  271.          les     di,SegTab         ;Addr of segment table
  272.          mov     cx,TotSegs         ;Total # segments
  273.          mov     ax,ds             ;Seg Addr of interrupt in AX
  274.          cmp     ax,1500h         ;Is exection in DOS
  275.          ja     Int08_1         ;  No    : continue
  276.          inc     DosCntLo         ;Bump the DOS hit count
  277.          jnz     Int08_0         ;        .
  278.          inc     DosCntHi         ;        .
  279. Int08_0:     jmp     Int08_H         ;        .
  280. Int08_1:
  281.          cmp     ax,0f000h         ;Is execution in ROM BIOS?
  282.          jb     Int08_A         ;  No    : continue
  283.          inc     BiosCntLo         ;Bump the BIOS hit count
  284.          jnz     Int08_2         ;        .
  285.          inc     BiosCntHi         ;        .
  286. Int08_2:     jmp     Int08_H         ;        .
  287. Int08_A:
  288.          cmp     ax,es:[di].SegAddr     ;Look for seg in the seg tab
  289.          je     Int08_B         ;Jump if found
  290.          add     di,type Seg1         ;Increment to next seg entry
  291.          loop     Int08_A         ;Loop thru entire table
  292.          inc     OtherCntLo         ;Seg not found, inc other cnt
  293.          jnz     Int08_H         ;        .
  294.          inc     OtherCntHi         ;        .
  295.          jmp     short Int08_H         ;        .
  296. Int08_B:
  297.          inc     HitCntLo         ;Seg found in table, hit cnt
  298.          jnz     Int08_B1         ;        .
  299.          inc     HitCntHi         ;        .
  300. Int08_B1:
  301.          mov     cx,es:[di].LinCnt     ;Cnt of Line # entries in seg
  302.          or     cx,cx             ;Is it zero?
  303.          jz     Int08_E         ;  Yes : skip line # check
  304.          lds     bx,es:[di].LinPtr     ;Get pointer to line # tab
  305.          cmp     si,[bx].OfsAddr     ;Int ofs > highest line #
  306.          ja     Int08_E         ;  Yes : skip line # check
  307. Int08_C:
  308.          cmp     si,[bx].OfsAddr     ;Locate line # entry in table
  309.          jae     Int08_D         ;Jump when found
  310.          add     bx,type Ofs1         ;Increment to next line entry
  311.          loop     Int08_C         ;Loop thru entire table
  312.          jmp     short Int08_E         ;Skip line # entry at end
  313. Int08_D:
  314.          inc     [bx].OfsLoCnt         ;Inc cnt for line # entry
  315.          jnz     Int08_E         ;        .
  316.          inc     [bx].OfsHiCnt         ;        .
  317. Int08_E:
  318.          mov     cx,es:[di].PubCnt     ;Cnt of Public entries in seg
  319.          or     cx,cx             ;Is it zero?
  320.          jz     Int08_H         ;  Yes : skip public check
  321.          lds     bx,es:[di].PubPtr     ;Get pointer to public table
  322. Int08_F:
  323.          cmp     si,[bx].OfsAddr     ;Locate public entry in table
  324.          jae     Int08_G         ;Jump when found
  325.          add     bx,type Ofs1         ;Inc to next public entry
  326.          loop     Int08_F         ;Loop thru entire table
  327.          jmp     short Int08_H         ;Skip public entry at end
  328. Int08_G:
  329.          inc     [bx].OfsLoCnt         ;Inc cnt for public entry
  330.          jnz     Int08_H         ;        .
  331.          inc     [bx].OfsHiCnt         ;        .
  332. Int08_H:
  333.          pop     ds             ;Restore all registers
  334.          pop     es             ;        .
  335.          pop     di             ;        .
  336.          pop     si             ;        .
  337.          pop     dx             ;        .
  338.          pop     cx             ;        .
  339.          pop     bx             ;        .
  340.          dec     IntCnt          ;Decrement interrupt count
  341.          jnz     Int08_I         ;Not time to call ROM timer
  342.          mov     IntCnt,TIMER_INT_CNT     ;Reset interrupt counter
  343.          pop     ax             ;Restore final registers
  344.          pop     bp             ;        .
  345.          jmp     OldInt08         ;Let old vector EOI & IRET
  346. Int08_I:
  347.          mov     al,EOI_CODE         ;Send the EOI to the 8259
  348.          out     I8259_EOI_PORT,al     ;        .
  349.          pop     ax             ;Restore final regiaters
  350.          pop     bp             ;        .
  351.          iret                 ;Return from interrupt
  352. Int08         endp
  353.  
  354.          EndCodeSeg PRFA
  355.          end
  356.  
  357.